package unilearn.facade;

import java.sql.*;
import java.util.Vector;
import javax.naming.*;

import unilearn.da.DASubject;
import unilearn.domain.Subject;

/**
 * @author Krish Nair, 5418763
 * @author Yin Zhang, 5393558
 * @version 0.1 Apr 30, 2008, initial creation
 * @version 0.2 May 10 2008, add createNewSubject, updateOldSubject function
 */
public class SubjectFacade
{
	public static Vector<Subject> getAllSubjects() throws SQLException, NamingException
	{
		return DASubject.getAllSubjects();
	}

	public static Subject getSubjectByID(long subjectID) throws SQLException, NamingException
	{
		Subject sub = DASubject.getSubjectByID(subjectID);

		sub.setAssignment(AssignmentFacade.getAssignmentBySubject(subjectID));

		return sub;
	}

	public static Subject getSubjectByCode(String subjectCode) throws SQLException,
		NamingException
	{
		return DASubject.getSubjectByCode(subjectCode);
	}
	
	public static long createNewSubject(Subject subject) throws SQLException, NamingException
	{
		return DASubject.insertSubject(subject);
	}
	
	public static void updateOldSubject(long subjectID, Subject subject) throws SQLException, NamingException
	{
		DASubject.updateSubject(subjectID, subject);
	}
}
